<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
	defined('_JEXEC') or die('Retricted Access');
	
	global $jbconfig;
	$script_jquery_tinymce = JURI::root()."components/com_jajobboard/js/jquery.tinymce.js";
	$script_tinymce = JURI::root()."plugins/editors/tinymce/jscripts/tiny_mce/tiny_mce.js";
  		
	$user = &JFactory::getUser();
	$editor = &JFactory::getEditor();
	JHTML::_('behavior.tooltip');
	$profile_list = $this->profile_list;
	$items = $this->items;
	$db = JFactory::getDBO();
	$arr_exc_field = array('views','apply_type','direct_url');
	
	$arr_applyform_id = array();
	for ($i=0;$i<count($items);$i++)
	{
		$arr_applyform_id[] = 'message'.$items[$i]->id.'-editor';
	}
	JHTML::_('behavior.modal', 'a.modal');
	
	// Google Map config
	$mapLocation = $jbconfig['general']->get('map_ja_jobs', "location_id");
?>
<div id="jobboard-content">
<?php rendfield_JS();?>
<script type="text/javascript" src="<?php echo $script_tinymce;?>"></script>
<script type="text/javascript">
/* <![CDATA[ */	
var num_job = <?php echo count($items); ?>;
tinyMCE.init({
   theme : "simple",
   mode: "exact",
   elements : "<?php echo implode(',',$arr_applyform_id); ?>",
   setup : function(ed) {
				      ed.onChange.add(function(ed, l) {
				          moveContent(ed.id);
				      });
				  	 },	
   theme_advanced_toolbar_location : "top",
   theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
   + "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
   + "bullist,numlist,outdent,indent",
   theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
   +"undo,redo,cleanup,code,separator,sub,sup,charmap",
   theme_advanced_buttons3 : "",
   height:"220px",
   width:"550px",
   file_browser_callback : 'myFileBrowser'
 });
/* ]]> */		
</script>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
    function submitbutton_view(pressbutton,item_id){
        var form_id = 'adminForm_'+item_id;
        var formid = document.getElementById(form_id);
        if(pressbutton == 'sendjob'){
            var send = document.getElementById('sendjob');
            if(send.style.display == 'none'){
                send.style.display = 'block';
            } else {
                send.style.display = 'none' ;
            } 
            window.location.href = '#sendjob';
            return false; 
        } else {
        	
            formid.task.value = pressbutton;
            formid.submit();
        }
    }
    
    function update_attachment(text,field_name,job_id)
    {
    	var display_text = text.lastIndexOf('/');
    	display_text = text.substr(display_text+1);
    	if ($('display_'+field_name+'_'+job_id))
    		$('display_'+field_name+'_'+job_id).value = display_text;
    	if ($(field_name+'_'+job_id))
    		$(field_name+'_'+job_id).value = text;
    	if (document.getElementById('sbox-window'))
		document.getElementById('sbox-window').close();
    }
    
    function show_div_content(id,item_id){
        var ele2 = document.getElementById('applyjob_' + item_id);
        var ele3 = document.getElementById('add_note_' + item_id);
        if(id == 'applyjob_'+item_id){
            if(ele2.style != null){
                ele2.style.display = ele2.style.display == 'none' ? 'block' : 'none';
            }
            if (ele3) ele3.style.display = 'none';
        } else if (id == 'add_note_'+item_id){
        	if(ele3.style != null){
                ele3.style.display = ele3.style.display == 'none' ? 'block' : 'none';
            if (ele2) ele2.style.display = 'none';    
            }
        }
    }
    
	function check(opt_obj,order_item)
	{
		attachment = document.getElementById("attachment_button"+order_item);
		
		if (opt_obj.value==1){
			attachment.innerHTML = '';		
		}else{
			attachment.innerHTML = '<?php echo JText::_("Upload file"); ?>';
		}		
	}
        
    function appendemail(){
        var formemail = document.sendmail;
        
        var message = tinyMCE.get('message');
        var youremail = formemail.youremail;
        message.setContent(message.getContent() + " " +  youremail.value);
    }
    
   function select_apply_type(type_value,item_id)
    {    	
    	div_direct = document.getElementById('direct_url_'+item_id);
		//div_inlinked = document.getElementById('inlinked_'+item_id);
		div_write = document.getElementById('write_message_'+item_id);
    	switch (type_value)
    	{
    		case '1':
    			div_direct.style.display = 'block';
    			div_write.style.display = 'none';
    			//div_inlinked.setStyle('display','none')
    			break;
    		case '2':
    			div_direct.style.display = 'none';
    			div_write.style.display = 'none';
    			//div_inlinked.setStyle('display','block')
    			break;
    		case '3':
    			div_direct.style.display = 'none';
    			div_write.style.display = 'block';
    			//div_inlinked.setStyle('display','none')
    			break;
    	}
    }

/* ]]> */
</script>

<?php if($items){?>
<?php for ($item_count = 0;$item_count<count($items);$item_count++) {
	$item = $items[$item_count];
	
	global $jbconfig;	
	$duration_standard_post = $jbconfig ['posts']->get ( 'posts_display_days', 30 );
	
	if ( (!$user->id || $item->user_id!=$user->id) &&	($item->status!='Approved'|| ( time()-strtotime($item->effected_date) > $duration_standard_post*24*60*60 ) ) )
	{
		JError::raiseNotice(0,JText::_('Sorry, this job is not available now'));
	}
	else 
	{
	JFilterOutput::objectHTMLSafe( $item );
	if (strpos($item->apply_type,'2'))
		$item->apply_type='3';
	$this->item = $item;
	$temp_user = JFactory::getUser($item->user_id);
	$temp_user->username = str_replace('.','()',$temp_user->username);
	require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'.DS.'ja_applications.php');
	$this->application = new JobBoardTableJA_Applications($db);
	
	if (isset($this->notes[$item->id]))
		$this->note = $this->notes[$item->id];
	else 
	{
		require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'.DS.'ja_notes.php');
		$this->note = new JobBoardTableJA_Notes($db);
	}
	$alias = JFilterOutput::stringURLSafe($item->title);
?>
<div id="ja-splitcontent">
<h2><?php echo $this->item->title; ?></h2>
<form id="adminForm_<?php echo $item->id; ?>" name="adminForm_<?php echo $item->id; ?>" action="<?php echo JURI::root();?>index.php" method="post">
<?php if((getCurrentUserType() == JBJOB_SEEKER_USER) || (getCurrentUserType() == 'Guest')){ ?>
	<div style="float: right;">
		<!-- AddThis Button BEGIN -->
		<a href="http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4a764a015f702d7f" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()">
			<img src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" style="border: 0pt none ;" width="125" height="16">
		</a>
		<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a764a015f702d7f"></script>

		<!-- AddThis Button END -->
	</div>
<?php } ?>
  <div class="moduletable job-box">
  	<h3><?php echo JText::_('Company Profile')?></h3>
    <table class="tabledata jobdetails">
        <?php if ($profile_list[$item->id]) {?>
        <tr>
        	<td width="20%">
        	<a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='. $temp_user->username.'&Itemid='.$this->Itemid ); ?>" title="<?php echo JText::_('Company profile'); ?>">
        		<?php
        		for ($i=0;$i<count($this->profile_editFieldList);$i++)
        			if ($this->profile_editFieldList[$i]->field_name=='logo')
        			{
						if ($profile_list[$item->id]->logo)
        					echo rendfield($profile_list[$item->id],$this->profile_editFieldList[$i],false,true,true);
        			}
        		?>
			</a>
        	</td>
        	<td>
        		<h4 class="co-name">
	        		<?php $alias = JFilterOutput::stringURLSafe($profile_list[$item->id]->company); ?> 
	        		<a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='. $temp_user->username ); ?>" title="<?php echo JText::_('Company profile'); ?>">
	              <strong>
	              	<?php
	              		for ($i=0;$i<count($this->profile_editFieldList);$i++)
		        			if ($this->profile_editFieldList[$i]->field_name=='company')
		        			{
								if ($profile_list[$item->id]->company)
		        					echo rendfield($profile_list[$item->id],$this->profile_editFieldList[$i],false,true,true);
		        			} 
	              	?>
	              </strong>
	            </a>
            </h4>
            <div class="co-des">
							<?php
								for ($i=0;$i<count($this->profile_editFieldList);$i++)
			        			if ($this->profile_editFieldList[$i]->field_name=='short_desc')
			        			{
									if ($profile_list[$item->id]->short_desc)
			        					echo rendfield($profile_list[$item->id],$this->profile_editFieldList[$i],false,true,true);
			        			} 
							?>
						</div>
                <br/>
                
        	</td>
        </tr>
        <?php } else { ?>
        <tr>
        	<td>
        		<font color="Red">
        			<?php echo JText::_('The profile for this job is not exist');  ?>
        		</font>
        		
        	</td>
        </tr>
        <?php } ?>
    </table>
  </div>
       
  <div class="moduletable job-box">        
    <table class="tabledata jobdetails">
      <?php
      $k=0;
      $firstIndex = findFirstField($item,$this->fieldlist);
      $lastIndex = findLastField($item,$this->fieldlist);
      for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ ){
	      if (!in_array($this->fieldlist[$i]->field_name,$arr_exc_field)){
	          $field = $this->fieldlist[$i];
	      }
	      else continue;
	      
	      if($field->display=='admin_only' && $user->aid<2) continue;
	      
	      if($field->display=='hide_all' || $field->display=='hide_on_view') continue;
	      
	      $input = rendfield($item, $field, false, true, true);
      
      if($field->field_type=='SEPERATOR'){?>
    </table>
	</div>
    <div class="moduletable job-box"> 
  		<?php if($input!=''){?>
		<h3><?php echo $input;?></h3>
		<?php }?>
		<table class="tabledata jobdetails">
	    <?php }else{
			      	$classname_sp = '';
			      	if ($i==$firstIndex)
			      		$classname_sp = ' first ';
			      	elseif ($i==$lastIndex)
			      		$classname_sp = ' last ';
					
			      	$classname = $classname_sp.'sectiontableentry'.($k+1);
			      	
			      ?>
			   		<tr class="<?php echo $classname; ?>">
				        <td width="20%" class="jajb-title">
				        	<?php echo JText::_($field->label); ?>:
				        </td>
			        	<td width="80%">
				           	<?php echo $input;?>
				           	
				           	<?php 
				           	// Check to show Google Map
				           	if( $field->field_name == $mapLocation && $input != "") {?>
				           	{jamap to_location='<?php echo $input;?>'}
				           	<?php }?>
				           	
				            <?php if($field->field_name=='title' && $this->item->is_hotjob){?>
				           	<sup style="float: right; color: red; font-weight: bold;"><?php echo JText::_(' Featured Job')?></sup>
				           <?php }?>
			        	</td>
			      	</tr>
			    	<?php $k = 1 - $k;
   			}
  		}?>
  	</table>
  </div>
      
	<input type="hidden" name="cid[]" value="<?php echo $item->id; ?>" />
	<input type="hidden" name="alias" value="<?php echo $alias; ?>" />
	<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
	<input type="hidden" name="view" value="jajobs" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="layout" value="duplicate" />
  <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>

  <div class="moduletable job-tools">
    <table class="tabledata jobdetails">
      <tr>
        <?php if(JRequest::getVar('step') == 'verify') {
        	if (JRequest::getVar('is_newjob'))
        		$new_task = 'done_new';
        	else 	
        		$new_task = 'done_update';
        		
        ?>
        <td>
            <a class="button" href="<?php echo 'index.php?option='. JBCOMNAME .'&view=jajobs&layout='.$new_task.'&cid[]='.$item->id. '&Itemid='. $this->Itemid ; ?>"><?php echo JText::_('Done'); ?></a>&nbsp;
            <a class="button" href="<?php echo JURI::root().'index.php?option='. JBCOMNAME .'&view=jajobs&layout=jaform&cid[]='.$item->id. '&alias='.$alias .'&Itemid='.$this->Itemid; ?>"><?php echo JText::_('Modify'); ?></a>
        </td>
        <?php } else {?>
        
        <td style="text-align:right !important;border-bottom: 1px solid #E5E5E5 !important;">
        	<img alt="<?php echo JText::_('Back'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Undo-16x16.png'?>" title="<?php echo JText::_('Back'); ?>">
           	&nbsp;
			<a title="Back" href="javascript:window.history.go(-1);">
				<span style="vertical-align: top ! important;"><?php echo JText::_('Back'); ?></span>
			</a>
           	&nbsp;
           	
        	<img title="<?php echo JText::_('Viewed number'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/chart_bar.gif' ?>" alt="<?php echo JText::_('Viewed number'); ?>" />
           	&nbsp;
           	<span style="vertical-align: top !important;"><?php echo JText::_('Hits').':'.$this->item->views; ?></span>
           	&nbsp;
            <?php if($item->user_id == $user->id && $item->user_id!=0){?>
            	<?php //if($item->is_hotjob) $layout = 'japremiumform'; else 
            	$layout = 'jaform';?>
                <img title="<?php echo JText::_('Edit job'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_edit.png' ?>" alt="<?php echo JText::_('Edit job'); ?>" />
                &nbsp;
                <a href="<?php echo JURI::root().'index.php?option='. JBCOMNAME .'&view=jajobs&layout='.$layout.'&cid[]='. $item->id; ?>" >
                	<span style="vertical-align: top !important;"><?php echo JText::_('Edit job'); ?></span>
                </a> 
                &nbsp;
               <img title="<?php echo JText::_('Delete job'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_delete.gif' ?>" alt="<?php echo JText::_('Delete job'); ?>" />
               &nbsp;
                <a href="javascript:submitbutton_view('remove',<?php echo $item->id; ?>);" onclick="return confirm('<?php echo JText::_('Do you want to delete this job?').'?';?>')">
               		<span style="vertical-align: top !important;"><?php echo JText::_('Delete job'); ?></span>
               	</a> 
               	&nbsp;
                <img title="<?php echo JText::_('Clone'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/copy-16x16.png' ?>" alt="<?php echo JText::_('Clone'); ?>" />                
                &nbsp;
                <a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jajobs&layout=duplicate&cid[]='. $item->id.'&Itemid='.$this->Itemid); ?>" >
                	<span style="vertical-align: top !important;"><?php echo JText::_('Clone'); ?></span>
                </a> 
                &nbsp;
            <?php } else if((getCurrentUserType() == JBJOB_SEEKER_USER) || (getCurrentUserType() == 'Guest')){
            				if(getCurrentUserType() == JBJOB_SEEKER_USER && !check_in_shortlist($user->id,$item->id,'ja_jobs')) {
            ?>
			<img title="<?php echo JText::_('Favorite'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Favorites-16x16.png' ?>" alt="<?php echo JText::_('Favorite'); ?>" />
			&nbsp;
			<a href="javascript:submitbutton_view('starred',<?php echo $item->id; ?>)"  >
				<span style="vertical-align: top !important;"><?php echo JText::_('Set as Favorite'); ?></span>
			</a>
			&nbsp;
		<?php  } ?>
		<span id="button_apply_<?php echo $item->id; ?>">
		<?php 
			
				
		if ( ((isset($this->app_list[$item->id]) && $jbconfig['posts']->get('allow_apply_several_time',0))||(!isset($this->app_list[$item->id])))&&($item->apply_type!='-1')) { 
				$item->apply_type = str_replace('-1,', '', $item->apply_type);
				$item->apply_type = str_replace(',-1', '', $item->apply_type);
		?>
                <img title="<?php echo JText::_('Apply job'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Check-16x16.png' ?>" alt="<?php echo JText::_('Apply job'); ?>" />
                &nbsp;
                <?php if (count(array_intersect(explode(',',$this->item->apply_type),explode(',',$jbconfig['posts']->get('apply_option'))))>0&&count(explode(',',$this->item->apply_type))==1&&$this->item->apply_type=='1'&& ( substr($this->item->direct_url,0,7)=='http://' || substr($this->item->direct_url,0,8)=='https://') ) {?> 
                 <a target="_blank" href="<?php echo $this->item->direct_url; ?>" >
                	<span style="vertical-align: top !important;"><?php echo JText::_('Apply'); ?></span>
                </a>
                <?php } else { ?>
                <a href="javascript:void(0)" onclick="show_div_content('applyjob_<?php echo $item->id; ?>','<?php echo $item->id; ?>')" >
                	<span style="vertical-align: top !important;"><?php echo JText::_('Apply'); ?></span>
                </a>
                &nbsp;
                <?php } ?>
        <?php } ?>
        		</span>
                <?php if (!$this->note->id) {?>
                &nbsp;
                &nbsp;
                <span id="div_addnote_button_<?php echo $item->id; ?>">
        		<img title="<?php echo JText::_('Add note'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Add-16x16.png' ?>" alt="<?php echo JText::_('Add note'); ?>" /> 
                 &nbsp;
                &nbsp;
				<a href="javascript:void(0)" onclick="show_div_content('add_note_<?php echo $item->id; ?>','<?php echo $item->id; ?>')" >
                	<span style="vertical-align: top !important;"><?php echo JText::_('Add note'); ?></span>
                </a>
                &nbsp; &nbsp;
                </span>
        <?php } ?> 
            <?php } 
            ?>
            
        </td>
        <?php } ?>
      </tr>
    </table>
  </div>
  <div style="clear:both"></div>
</div>


<!-- Form: Send to friend-->
<?php if(getCurrentUserType() != JBEMPLOYER_USER && ((isset($this->app_list[$item->id]) && $jbconfig['posts']->get('allow_apply_several_time',0))||(!isset($this->app_list[$item->id])))) {?> 
	<!-- Form: Apply Job-->	
	<a name="apply-job-<?php echo $this->item->id?>" id="apply-job-<?php echo $this->item->id?>"></a>
	<div style="display:none; border: 1px solid rgb(238, 238, 0); padding: 0.5em; margin-top: 20px; color: red" id="app_err_<?php echo $this->item->id; ?>"></div>
	<div id="applyjob_<?php echo $item->id; ?>"  <?php if (!JRequest::getVar('app_postback')) {?>style="display:none; max-width:900px; clear:both"<?php } ?>>		
		<fieldset>			
			<?php 			
			if( is_file(dirname(__FILE__).DS.'applytojob.php') )
				include(dirname(__FILE__).DS.'applytojob.php');
			else include( JPATH_SITE.DS."components".DS."com_jajobboard".DS."views".DS."jajobs".DS."tmpl".DS.'applytojob.php');
			?>
		</fieldset>
	</div>
<?php }?>

<div id="add_note_<?php echo $item->id; ?>" class="moduletable" <?php if (!$this->note->id) {?>	style="display:none; max-width:900px; clear:both" <?php } ?>>
	<?php 
	if( is_file(dirname(__FILE__).DS.'add_notes.php') )
				include(dirname(__FILE__).DS.'add_notes.php');
	else include( JPATH_SITE.DS."components".DS."com_jajobboard".DS."views".DS."jajobs".DS."tmpl".DS.'add_notes.php');	
	?>
</div>
<div style="clear: both; margin-top: 20px;"></div>
<?php } ?>
<?php } }?>


<?php if ($this->pagination->total>5) {?>
<div style="text-align:center">
<form name="adminForm" action="index.php" method="POST">
	<?php echo $this->pagination->getPagesLinks(); ?>
	<br/>
	<?php echo $this->pagination->getPagesCounter(); ?>
	<input type="hidden" name="boxcheck" value="0" />
	<input type="hidden" name="cid[]" value="<?php echo implode(',',JRequest::getVar('cid')); ?>" />
 	<input type="hidden" name="option" value="com_jajobboard" />
	<input type="hidden" name="view" value="jajobs" />
	<input type="hidden" name="layout" value="jaview" />
	<input type="hidden" name="limitstart" value="<?php echo $this->pagination->limitstart; ?>" />
	<input type="hidden" name="limit" value="<?php echo $this->pagination->limit; ?>" />
    <input type="hidden" name="task" value="" />
	<input type="hidden" name="Itemid" value="<?php echo $this->Itemid;?>" />
</form>
</div>
<?php } ?>
</div>
